<!DOCTYPE html>
<html>
<head>
    <title>畅销套餐</title>
</head>

<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/echarts.min.js"></script>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="height:500px;border:1px solid #ccc;padding:10px;">
</div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts图表
    var myChart = echarts.init(document.getElementById('main'));
    myChart.setOption({
        title: {
            text: '套餐销量情况',
            x: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            data: []
        },
        toolbox: {
            show : true,
            feature : {
                mark : {show: true},
                dataView : {show: true, readOnly: false},
                magicType : {
                    show: true,
                    type: ['pie', 'funnel'],
                    option: {
                        funnel: {
                            x: '25%',
                            width: '50%',
                            funnelAlign: 'left',
                            max: 1548
                        }
                    }
                },
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        series: [
            {
                name: '访问来源',
                type: 'pie',
                radius: '55%',
                center: ['50%', '60%'],
                data: [],
                itemStyle:{
                    emphasis:{
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0,0,0,0.5)'
                    }
                }
            }
        ]
    });
    //    myChart.showLoading();    //数据加载完之前先显示一段简单的loading动画

    var mapOnlyKey = [];  //套餐类型
    var mapKeyValue = [];
    var mapOnlyValue = [];
    var info = {"opt": "pie"};
    $.post("/getPieData", info, function (data) {
        console.log(mapOnlyKey);
        for (var i = 0; i < data.length; i++) {
            mapOnlyKey.push(data[i].taocan);
            mapKeyValue.push({"name": data[i].taocan, "value": Math.round(data[i].total)});
            mapOnlyValue.push(data[i].total);
        }
        console.log(mapOnlyKey);
        console.log(mapKeyValue);
        console.log(mapOnlyValue);
        myChart.setOption({
            legend: {
                data: mapOnlyKey
            },
            series: [{
                name: "数量",
                data: mapKeyValue
            }]
        })
    },'json');


</script>
</body>
</html>